import App from './App.vue'
import router from './router'


import mavonEditor from 'mavon-editor'
import 'mavon-editor/dist/css/index.css'

import MyScroll from "./components/scroll/scroll"
import store from "./store/index"
import Vue from 'vue'
import VueSocketIO from 'vue-socket.io'


Vue.use(new VueSocketIO({
  debug: false, //设置true可以让你的控制台文字变颜色，更好的调试阅读
  connection: 'http://www.yemengshen.cn',
  // connection: 'http://www.yemengs.cn',
  // connection: 'http://localhost:4000',
  // vuex: {
  //   store,
  //   mutationPrefix: "SOCKET_",
  //   actionPrefix: "SOCKET_"
  // }
}))

// use
Vue.use(mavonEditor)

Vue.directive('highlight', (el) => {
  let blocks = el.querySelectorAll('pre code')
  blocks.forEach((block) => {
    hljs.highlightBlock(block)
  })
})

// 转换时间的方法
Vue.prototype.$dateFormat = (originVal) => {
  let old = new Date(originVal)
  let now = new Date()
  //获取old具体时间
  let d = old.getTime()
  let h = old.getHours()
  let m = old.getMinutes()
  let Y = old.getFullYear()
  let M = old.getMonth() + 1
  let D = old.getDate()
  //获取now具体时间
  let nd = now.getTime()
  let nh = now.getHours()
  let n = now.getMinutes()
  let nY = now.getFullYear()
  let nM = now.getMonth() + 1
  let nD = now.getDate()

  //当天的时间
  if (D === nD && M === nM && Y === nY) {
    if (h < 10) {
      h = "0" + h
    }
    if (m < 10) {
      m = "0" + m
    }
    return "今天" + h + ":" + m
  }
  //昨天时间
  if (D + 1 === nD && M === nM && Y === nY) {
    if (h < 10) {
      h = "0" + h
    }
    if (m < 10) {
      m = "0" + m
    }
    return "昨天 " + h + ":" + m
  } else {
    //大于两天
    return Y + "-" + M + "-" + D
  }
}


Vue.config.productionTip = false

// 事件车（事件总线）
Vue.prototype.$EventBus = new Vue()

//  转换播放量
Vue.filter("playCount", function(count) {
  if (count > 10000) {
    count = Math.ceil(count / 10000) + "万"
  }
  return count
})

// 转换播放时间
Vue.filter('playTimeFormat', function(originVal) {
  let duration = originVal
  let min = parseInt(duration / 1000 / 60)
  if (min < 10) {
    min = '0' + min
  }
  let sec = parseInt((duration / 1000) % 60)
  if (sec < 10) {
    sec = '0' + sec
  }
  return `${min}:${sec}`
})
// 转换日期
Vue.filter('dateFormat', function(originVal) {
  const dt = new Date(originVal)
  const y = dt.getFullYear()
  const m = (dt.getMonth() + 1 + '').padStart(2, '0')
  const d = (dt.getDate() + '').padStart(2, '0')

  const hh = (dt.getHours() + '').padStart(2, '0')
  const mm = (dt.getMinutes() + '').padStart(2, '0')
  const ss = (dt.getSeconds() + '').padStart(2, '0')

  return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
})
Vue.filter('chatDateFormate', (originVal) => {
  let old = new Date(originVal)
  let now = new Date()
  //获取old具体时间
  let d = old.getTime()
  let h = old.getHours()
  let m = old.getMinutes()
  let Y = old.getFullYear()
  let M = old.getMonth() + 1
  let D = old.getDate()
  //获取now具体时间
  let nd = now.getTime()
  let nh = now.getHours()
  let n = now.getMinutes()
  let nY = now.getFullYear()
  let nM = now.getMonth() + 1
  let nD = now.getDate()

  //当天的时间
  if (D === nD && M === nM && Y === nY) {
    if (h < 10) {
      h = "0" + h
    }
    if (m < 10) {
      m = "0" + m
    }
    return "今天" + h + ":" + m
  }
  //昨天时间
  if (D + 1 === nD && M === nM && Y === nY) {
    if (h < 10) {
      h = "0" + h
    }
    if (m < 10) {
      m = "0" + m
    }
    return "昨天 " + h + ":" + m
  } else {
    //大于两天
    return Y + "-" + M + "-" + D
  }
})


Vue.component("my-scroll", MyScroll)

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')